#include "stdafx.h"
#include "detail/bmock_message.hpp"

const char *const bmock::NULL_STR   = "<NULL>";
const char *const bmock::IGNORE_STR = "<IGNORE>";

static const char *const error_message[] = {
	"Invalid raw mem structure for argument '%1%' supplied"
	,"InOut Raw Memory argument '%1%' pad length (expected == actual)"
    ,"Raw memory argument '%1%': (actual length <= maximal length) check"
	,"Raw memory argument '%1%': output read >maximal length"
    ,"Argument '%1%' value (expected == actual) check"
	,"Null expected/null supplied consistency check for pointer argument '%1%'"
	,"Argument '%1%' value update failed"
	,"Mock function (expected == call) check"
	,"Function call '%1%' has not been received"
	,"Unexpected BMOCK_REPLAY"
	,"Unexpected BMOCK_VERIFY"
	,"Unexpected function call (m.b. BMOCK_REPLAY is missing)"
	,"Unexpected destructor of bmock::control"
	,"Unexpected BMOCK_EXPECT, BMOCK_EXPECT_RETURN or BMOCK_EXPECT_THROW"
	,"Invalid BMOCK_CHECK for non-void function, BMOCK_CHECK_RETURN required"
	,"Unexpected bmock::control::get_result method call"
	,"Invalid return value type supplied"
	,"Invalid BMOCK_EXPECT, BMOCK_EXPECT_RETURN or BMOCK_EXPECT_THROW for non-mock function"
	,"Unexpected EXPECT_CALLBACK"
	,"BMOCK Console mode does not support double pointers except for void, char, and const char"
	,"Invalid input binary data: %1%"
	,"setup failed: '%1%' exception thrown"
	,"setup failed"
	,"test failed: '%1%' exception thrown"
	,"test failed"
	,"teardown failed: '%1%' exception thrown"
	,"teardown failed"
	,"Unexpected BMOCK_STUB, BMOCK_STUB_RETURN or BMOCK_STUB_THROW"
	,"do not use in_raw_mem macro with RAW(IN"
	,"multiple stubs for the same function"
	,"Invalid use of test mode functions in console mode"
	,"Invalid use of console mode functions in test mode"
	,"Invalid parameter in mock declaration"
	,"Argument '%1%' value (expected == actual) check failed"
	,"Illegal call times range"
	,"Unexpected BMOCK_EXPECT_NON_STRICT, BMOCK_EXPECT_NON_STRICT_RETURN or BMOCK_EXPECT_NON_STRICT_THROW"
	,"Macro argument '%1%' appears more than once in the argument list"
	,"Number of macro arguments (not including this pointer) is not equal to number of function arguments"
};

std::string bmock::message(const error_code ec) {
	return error_message[ec];
}

static const char tag[] = "%1%"; 

std::string bmock::message(const error_code ec,const std::string &name, const std::string& extra_msg) {
	std::string                  msg = message(ec);
	const std::string::size_type pos = msg.find(tag);

	return msg.replace(pos,sizeof(tag)-1,name).append(extra_msg);
}
